package com.zp.crm.Controller.JwjlController;

import java.io.PrintWriter;
import java.util.Date;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.google.gson.Gson;
import com.zp.crm.entity.JwjlEntity.JwjlEntity;
import com.zp.crm.service.JwjlService.JwjlService;

@Controller
@RequestMapping("/jwjl")
public class JwjlController {
	
	@Resource
	public JwjlService jsjlService;
	
	@RequestMapping(value="/select",method=RequestMethod.POST)
	public void selectCode(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String code=request.getParameter("code");
		Map<String,Object> map=jsjlService.selectCode(code);
		String a=(String)map.get("message");
		try{
			PrintWriter out =response.getWriter();
			out.println(a);
		}catch (Exception e) {
			e.printStackTrace();
		}	
	}
	
	@RequestMapping(value="/insert",method=RequestMethod.POST)
	public void insert(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String code=request.getParameter("code");
		String jwdd=request.getParameter("jwdd");
		String jwgy=request.getParameter("jwgy");
		String jwxqxx=request.getParameter("jwxqxx");
		String jwbz=request.getParameter("jwbz");
		JwjlEntity entity=new JwjlEntity(code, new Date(), jwdd, jwgy, jwxqxx, jwbz);
		Map<String,Object> map=jsjlService.insert(entity);
		try{
			PrintWriter out =response.getWriter();
			String json=new Gson().toJson(map);
			out.println(json);
		}catch (Exception e) {
			e.printStackTrace();
		}	
	}
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public void JwjlDelete(HttpServletRequest request,HttpServletResponse response){
		response.setContentType("text/html;charset=utf-8");
		String idstr=request.getParameter("id");
		int id=0;
		if(idstr != null){
			id=Integer.parseInt(idstr);
		}
		Map<String,Object> map=jsjlService.delete(id);
		try{
			PrintWriter out =response.getWriter();
			String json=new Gson().toJson(map);
			out.println(json);
		}catch (Exception e) {
			e.printStackTrace();
		}	
		
	}
	
}
